<?php
namespace Home\Controller;
use Common\Controller\CommonController;

class MemberNoGoodsController extends CommonController {

    public function index()
    {
        $wd = I('wd');
        $map = [];
        if($wd){
            $map['goods_name'] = ['like', "%{$wd}%"];
        }
        list($list, $page) = $this->lists('MemberNoGoods', $map, 'id desc');
        if($list){
            foreach ($list as $key => &$row) {
                if(isset($user_arr[$row['user_id']])){
                    // $row['is_feedback'] = 1;
                }else{
                    // $row['is_feedback'] = 0;
                }
            }
        }
        $this->assign('page',$page);
        $this->assign('list', $list);
        $this->display();
    }

    public function add()
    {
        if(IS_POST){
            $data = I('post.');

            $model = M('MemberNoGoods');

            $id = $model->add($data);
            if($id){
                $this->ajaxReturn(array('s'=>true,'m'=>'添加成功', 'url'=>U('index')));
            }else{
                $this->ajaxReturn(array('s'=>false,'m'=>'添加失败!'));
            }
        }else{
            $this->display();
        }
    }

    public function edit()
    {
        $id = I('id');
        if(IS_POST){
            $data = I('post.');

            $model = M('MemberNoGoods');

            $res = $model->where(['id'=>$id])->save($data);
            if($res!==false){
                $this->ajaxReturn(array('s'=>true,'m'=>'修改成功', 'url'=>U('index')));
            }else{
                $this->ajaxReturn(array('s'=>false,'m'=>'修改失败!'));
            }
        }else{
            $info = M('MemberNoGoods')->where(['id'=>$id])->find();
            $this->assign('info', $info);
            $this->display();
        }
    }

    public function del(){
        $id = I('id');
        $res = M('MemberNoGoods')->where(['id'=>$id])->delete();
        if($res){
            $this->ajaxReturn(array('s'=>true,'m'=>'删除成功', 'url'=>U('index')));
        }else{
            $this->ajaxReturn(array('s'=>false,'m'=>'删除失败!'));
        }
    }
}